package org.flowers.unbeaten.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.flowers.unbeaten.base.entity.BaseEntity;
import org.flowers.unbeaten.base.entity.Department;
import org.flowers.unbeaten.logging.aop.annotation.Logging;
import org.flowers.unbeaten.logging.aop.enums.BusinessType;
import org.flowers.unbeaten.service.IDepartmentService;
import org.flowers.unbeaten.util.DataResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 部门 前端控制器
 * </p>
 *
 * @author RyanWang
 * @since 2021-07-15
 */
@Api(tags = "后台系统-部门管理")
@RestController
@RequestMapping("/department/department")
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    @PostMapping("/list")
    @ApiOperation(value = "分页获取部门列表接口")
    @Logging(title = "部门管理", describe = "分页获取部门列表", type = BusinessType.QUERY)
    @RequiresPermissions("department:department:list")
    public DataResult list(@RequestBody Department department, BaseEntity baseEntity) {
        return DataResult.success(departmentService.getDepartmentPageList(department, baseEntity));
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增部门接口")
    @Logging(title = "部门管理", describe = "新增部门", type = BusinessType.ADD)
    @RequiresPermissions("department:department:add")
    public DataResult add(@RequestBody Department department) {
        departmentService.add(department);
        return DataResult.success();
    }

    @PutMapping("/edit")
    @ApiOperation(value = "编辑部门接口")
    @Logging(title = "部门管理", describe = "编辑部门", type = BusinessType.EDIT)
    @RequiresPermissions("department:department:edit")
    public DataResult edit(@RequestBody Department department) {
        departmentService.edit(department);
        return DataResult.success();
    }

    @DeleteMapping("/delete/{ids}")
    @ApiOperation(value = "删除部门接口")
    @Logging(title = "部门管理", describe = "删除部门", type = BusinessType.REMOVE)
    @RequiresPermissions("department:department:delete")
    public DataResult delete(@PathVariable List<String> ids) {
        departmentService.delete(ids);
        return DataResult.success();
    }

    @GetMapping("/detail/{departmentId}")
    @ApiOperation(value = "部门详情接口")
    @Logging(title = "部门管理", describe = "部门详情", type = BusinessType.OTHER)
    @RequiresPermissions("department:department:detail")
    public DataResult detail(@PathVariable String departmentId) {
        departmentService.detail(departmentId);
        return DataResult.success();
    }

    @GetMapping("/tree/all")
    @ApiOperation(value = "递归查询所有的部门接口")
    @Logging(title = "部门管理", describe = "递归查询所有的部门", type = BusinessType.QUERY)
    public DataResult getAllDepartments() {
        return DataResult.success(departmentService.getDepartmentAllTree());
    }


}

